/*
 This file 'Switcher' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2015 Lincong

 Contact:  
 Email: lincong1987@gmail.com

 QQ: 159257119

 See Usage at http://www.jplatformx.com/firebird

 Create date: 2015-03-16 04:09
 */

define(function (require, exports, module) {

	require("Firebird.Model");

	Firebird.define("Firebird.data.Switcher", {
		extend: "Firebird.Model",
		statics: {
			get: function (value, array, key, rsKey) {
				var rs = "", key = key || "id", rsKey = rsKey || "name";
				$.each(array||[], function (i, n) {
					if (n[key] == value) {
						rs = n[rsKey];
						return false;
					}
				});
				return rs;
			},
			getByFilter: function (array, value, key, name) {
				return Firebird.Array.pluck(Firebird.Array.filter(array, function (item) {
					return Firebird.Array.indexOf((value||"").split(","), item[(key||"id")] + "") >= 0;
				}), (name || "name"));
			}
		}
	});

	module.exports = Firebird.data.Switcher;
});